define(function(require, exports, module) {
	"use strict";
	require("mui");
	require("jquery");
	require("../newOrder/dateInput.js");
	var abpdata = require("abpinit");
	var abp = abpdata.abpstart;
	mui.init({
		swipeBack: true //启用右滑关闭功能
	});
	require('http://g.alicdn.com/ilw/ding/0.8.9/scripts/dingtalk.js');
	//钉钉返回清除缓存
	var dingTalkNav = require('dd_config');

	$(function() {
		function clearSession() {
			sessionStorage.removeItem("chioceStaff");
			sessionStorage.removeItem("chioceStaffId");
			document.location.href = "../../src/chioceLibrary/chioceLibrary.html?dd_nav_bgcolor=FFFF943E";
		}
		//ios
		dingTalkNav.LeftNavBar(clearSession);
		//ad
		dingTalkNav.leftAndroid(clearSession);

		if(sessionStorage.chioceStaff && sessionStorage.chioceStaffId) {
			$("#whContact").text(sessionStorage.chioceStaff);
			$("#whContact").attr("data-id", sessionStorage.chioceStaffId);
		} else {
			$("#whContact").text("选择联系人");
			$("#whContact").attr("data-id", "");
		}

		var Serialdata = 'GP' + Math.floor(Math.random() * 1000);
		$('#whSerial').val(Serialdata);

		function newAddLibrary() {
			var option = {};
			var whSerial = $('#whSerial').val().trim();
			var whName = $('#whName').val().trim();
			var whAddress = $('#whAddress').val().trim();
			var whContact = $('#whContact').text().trim();
			var whContactMobile = $('#whContactMobile').val().trim();
			var notes = $('#notes').val().trim();
			var dataModel = {
				"whSerial": whSerial, //仓库编号
				"whName": whName, //仓库名称
				"isWhStorage": false, //是否开启储位
				"parentId": 0, //上级仓库 
				"notes": notes, //备注
				"whAddress": whAddress, //仓库地址 
				"whContact": whContact, //联系人 
				"whContactMobile": whContactMobile, //联系人手机
				"id": 0
			};

			abp.services.app.whInfo.create(dataModel, option).
			done(function(data) {
				mui.alert('<ul class="mui-row pop-tabmain"><li class="mui-col-xs-4 mui-col-sm-4" style="text-align: right;padding-right: 15px;"><a class="yuanico"><span>√</span></a></li><li class="mui-col-xs-8 mui-col-sm-8" style="text-align: left;line-height: 46px;">保存成功</li></ul>', "", function() {
					mui.back();
				}, 'div');
				sessionStorage.removeItem("chioceStaff");
				sessionStorage.removeItem("chioceStaffId");

			}).fail(function(data) {
				mui.alert('<ul class="mui-row pop-tabmain"><li class="mui-col-xs-4 mui-col-sm-4" style="text-align: right;padding-right: 15px;"><a class="yuanico"><span>√</span></a></li><li class="mui-col-xs-8 mui-col-sm-8" style="text-align: left;line-height: 46px;">您填写的信息不完整</li></ul>', "", function() {}, 'div');
			});
		}

		mui("body").on("tap", "#sub-btn", function() {
			newAddLibrary();
		});

	});
	/*a链接跳转问题*/
	mui('body').on('tap', 'a', function() {
		document.location.href = this.href + "?dd_nav_bgcolor=FFFF943E";
	});

});